package com.situ.web.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/setCookie")
public class SetCookieServlet extends HttpServlet{

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("CookieServlet.service()");
		Cookie cookie1  = new Cookie("goods", "IPhone");
		Cookie cookie2  = new Cookie("name", "zhangsan");
		// expiry an integer specifying the maximum age of the cookie in seconds; 
		// if negative, means the cookie is not stored; if zero, deletes the cookie
		cookie1.setMaxAge(10 * 60);
		resp.addCookie(cookie1);
		resp.addCookie(cookie2);
	}
}
